	*Data sets for the graphs

* Cognitive
* With scale invariance 
use "Y:\Fuyao_Erlfang\estimates\maturation\cog_add/bootsresults.dta", clear 
 
* Creating the transformations:
foreach num of numlist 2/4{
gen var`num'_2= (1.4^var`num')/(10*(1.4^var`num'+1))
}
gen var5_2=(1-1.4^var5)

gen var7_2=(1.4^var7)/((1.4^var7)+1)*4

gen var8_2=(var8) // Remove 1.4
foreach num of numlist 9/20{
local j = `num'-1
gen var`num'_2=var`j'_2+(var`num')	// Remove 1.4	
}
foreach num of numlist 21/31 {
gen var`num'_2=(1.4^var`num')		
}
foreach num of numlist 38/45{
gen var`num'_2=((1.1^var`num')/((1.1^var`num')+1))*4		//by 4
}
cap drop q
foreach var of varlist var1 var2_2-var5_2 var6 var7_2-var31_2 var32-var37 var38_2-var45_2 var46 var47{
sort `var'
gen q=_n
gen aux= `var' if q==25
egen `var'_lb= max(aux) 
drop aux
gen aux= `var' if q==975
egen `var'_ub= max(aux) 

drop aux
sum `var'
gen aux= r(sd)
egen `var'_sd= max(aux) 

drop q aux
}


keep var*sd var*lb var*ub 
gen q=_n
foreach num of numlist 1 6 32/37 46/47{
	rename var`num'_lb var_lb_`num'
	rename var`num'_ub var_ub_`num'
	rename var`num'_sd var_sd_`num'
	
}
foreach num of numlist 2/5 7/31 38/45{
	rename var`num'_2_lb var_lb_`num'
	rename var`num'_2_ub var_ub_`num'
	rename var`num'_2_sd var_sd_`num'
	
}
keep if q<4
reshape long var_lb_ var_ub_ var_sd_ , i(q) j(numero)
sort numero q
rename numero n
merge m:1 n using "Y:\Fuyao_Erlfang\estimates\maturation\cog_add/point_estimates_add_mat.dta"
drop _merge
drop additive 
rename m1 add_pe
keep if q==1
gen var=""
replace var ="Kbar" if n>7 & n<21
replace var=" $\sigma_{s,\ell}^{2}$" if n<32 & var==""
replace var="Delta" if var==""
drop if n>31 & n<38
drop if n<8
drop if n>45
drop q
gen level=substr(var1,-2,.)
destring level, replace
order  n var var1 level add_pe
*Last updated :09/22
saveold "Y:\Fuyao_Erlfang\estimates\maturation\Graphs/c/c_add.dta" , replace



* Multiplicative

global path "Y:\Fuyao_Erlfang\estimates\maturation\"
use "$path/cog_mul/bootsresults.dta", clear
* Creating the transformations:
foreach num of numlist 2/4{
gen var`num'_2= (1.4^var`num')/(10*(1.4^var`num'+1))
}
gen var5_2=(1-1.4^var5)

gen var7_2=(1.4^var7)/((1.4^var7)+1)*4

gen var8_2=1+(var8)  //ELIMINATES THE 1.4
foreach num of numlist 9/19{
local j = `num'-1
gen var`num'_2=var`j'_2+(var`num')	//ELIMINATES THE 1.4		
}
foreach num of numlist 20/30 37{
gen var`num'_2=(1.4^var`num')		
}
foreach num of numlist 38/45{
gen var`num'_2=((1.1^var`num')/((1.1^var`num')+1))*4		//by 4
}
cap drop q
foreach var of varlist var1 var2_2-var5_2 var6 var7_2-var30_2 var31-var36 var37_2-var45_2 var46 var47{
sort `var'
gen q=_n
gen aux= `var' if q==25
egen `var'_lb= max(aux) 
drop aux
gen aux= `var' if q==975
egen `var'_ub= max(aux) 

drop aux
sum `var'
gen aux= r(sd)
egen `var'_sd= max(aux) 

drop q aux
}


keep var*sd var*lb var*ub 
gen q=_n
foreach num of numlist 1 6 31/36 46/47 {
	rename var`num'_lb var_lb_`num'
	rename var`num'_ub var_ub_`num'
	rename var`num'_sd var_sd_`num'
	
}
foreach num of numlist 2/5 7/30 37/45{
	rename var`num'_2_lb var_lb_`num'
	rename var`num'_2_ub var_ub_`num'
	rename var`num'_2_sd var_sd_`num'
	
}
keep if q<4
reshape long var_lb_ var_ub_ var_sd_ , i(q) j(numero)
sort numero q

rename numero n
merge m:1 n using "$path/cog_mul/point_estimates_mul_mat.dta"
drop _merge
drop multiplicative 
rename m2 mul_pe
keep if q==1
cap drop var
gen var=""
replace var ="Kbar" if n>7 & n<20
replace var=" $\sigma_{s,\ell}^{2}$" if n<31 & var==""
replace var="Delta" if var==""
drop if n>30 & n<38
drop if n<8
drop if n>45
drop q
gen level=substr(var1,-2,.)
destring level, replace
order  n var var1 level mul_pe
*Last updated :09/22

saveold "$path/Graphs/c/c_mul.dta" , replace


* WithOut scale invariance 
*Additive

use "Y:\Fuyao_Erlfang\estimates\maturation\cog_level_add/bootsresults.dta", clear 
 
* Creating the transformations:
foreach num of numlist 2/4{
gen var`num'_2= (1.4^var`num')/(10*(1.4^var`num'+1))
}
gen var5_2=(1-1.4^var5)

gen var7_2=(1.4^var7)/((1.4^var7)+1)*4

gen var8_2=(var8) //ELIMINATES THE 1.4
foreach num of numlist 9/20{
local j = `num'-1
gen var`num'_2=var`j'_2+(var`num')	//ELIMINATES THE 1.4	
}
foreach num of numlist 21/31 {
gen var`num'_2=(1.4^var`num')		
}
foreach num of numlist 38/45{
gen var`num'_2=((1.1^var`num')/((1.1^var`num')+1))*4		//by 4
}
cap drop q
foreach var of varlist var1 var2_2-var5_2 var6 var7_2-var31_2 var32-var37 var38_2-var45_2 var46-var60{
sort `var'
gen q=_n
gen aux= `var' if q==25
egen `var'_lb= max(aux) 
drop aux
gen aux= `var' if q==975
egen `var'_ub= max(aux) 

drop aux
sum `var'
gen aux= r(sd)
egen `var'_sd= max(aux) 

drop q aux
}
* TAKING OUT THE OUTLIERS FROM VARIANCE 
foreach var of varlist var26_2 var31_2  {
drop `var'_sd
sort  `var'
gen q=_n
sum `var'
*sum `var' if `var'< r(max)
sum `var' if q<997
gen aux= r(sd)
egen `var'_sd= max(aux) 
drop aux q	
	
}
foreach var of varlist  var31_2  {
drop `var'_sd
sort  `var'
gen q=_n
sum `var'
*sum `var' if `var'< r(max)
sum `var' if q<992
gen aux= r(sd)
egen `var'_sd= max(aux) 
drop aux q	
	
}

keep var*sd var*lb var*ub 
gen q=_n
foreach num of numlist 1 6 32/37 46/60{
	rename var`num'_lb var_lb_`num'
	rename var`num'_ub var_ub_`num'
	rename var`num'_sd var_sd_`num'
	
}
foreach num of numlist 2/5 7/31 38/45{
	rename var`num'_2_lb var_lb_`num'
	rename var`num'_2_ub var_ub_`num'
	rename var`num'_2_sd var_sd_`num'
	
}
keep if q<4
reshape long var_lb_ var_ub_ var_sd_ , i(q) j(numero)
sort numero q
rename numero n
merge m:1 n using "Y:\Fuyao_Erlfang\estimates\maturation\cog_level_add/point_estimates_add_mat_wo.dta"
drop _merge
drop additive 
rename m1 add_pe
keep if q==1
gen var=""
replace var ="Kbar" if n>7 & n<21
replace var=" $\sigma_{s,\ell}^{2}$" if n<32 & var==""
replace var="Delta" if n>37 & n<46 & var==""
replace var="Beta1" if n>45 & n<59 & var==""

drop if n>31 & n<38
drop if n<8
drop if n>59
drop q
gen level=substr(var1,-2,.)
destring level, replace
order  n  var var1 level add_pe
*Last updated:09/22 9:40
saveold "Y:\Fuyao_Erlfang\estimates\maturation/Graphs/c/c_add_wo_si.dta" , replace

* Multiplicative
 use "Y:\Fuyao_Erlfang\estimates\maturation\cog_level_mul/bootsresults.dta", clear
* Creating the transformations:
foreach num of numlist 2/4{
gen var`num'_2= (1.4^var`num')/(10*(1.4^var`num'+1))
}
gen var5_2=(1-1.4^var5)

gen var7_2=(1.4^var7)/((1.4^var7)+1)*4

gen var8_2=1+(var8) //ELIMINATES THE 1.4
foreach num of numlist 9/19{
local j = `num'-1
gen var`num'_2=var`j'_2+(var`num')	//ELIMINATES THE 1.4	
}
foreach num of numlist 20/30 37{
gen var`num'_2=(1.4^var`num')		
}
foreach num of numlist 38/45{
gen var`num'_2=((1.1^var`num')/((1.1^var`num')+1))*4		//by 4
}
cap drop q
foreach var of varlist var1 var2_2-var5_2 var6 var7_2-var30_2 var31-var36 var37_2-var45_2 var46-var60{
sort `var'
gen q=_n
gen aux= `var' if q==25
egen `var'_lb= max(aux) 
drop aux
gen aux= `var' if q==975
egen `var'_ub= max(aux) 

drop aux
sum `var'
gen aux= r(sd)
egen `var'_sd= max(aux) 

drop q aux
}


keep var*sd var*lb var*ub 
gen q=_n
foreach num of numlist 1 6 31/36 46/60{
	rename var`num'_lb var_lb_`num'
	rename var`num'_ub var_ub_`num'
	rename var`num'_sd var_sd_`num'
	
}
foreach num of numlist 2/5 7/30 37/45{
	rename var`num'_2_lb var_lb_`num'
	rename var`num'_2_ub var_ub_`num'
	rename var`num'_2_sd var_sd_`num'
	
}
keep if q<4
reshape long var_lb_ var_ub_ var_sd_ , i(q) j(numero)
sort numero q

rename numero n
merge m:1 n using "Y:\Fuyao_Erlfang\estimates\maturation\cog_level_mul/point_estimates_mul_mat_wo.dta"
drop _merge
drop multiplicative
rename m2 mul_pe
keep if q==1
cap drop var
gen var=""
replace var ="Kbar" if n>7 & n<20
replace var=" $\sigma_{s,\ell}^{2}$" if n<31 & var==""
replace var="Delta" if  n>37 & n<46 & var==""
replace var="Beta1" if  n>45 & n<59 & var==""
drop if n>30 & n<38
drop if n<8
drop if n>58
drop q
gen level=substr(var1,-2,.)
destring level, replace
order  n  var var1 level mul_pe

saveold "Y:\Fuyao_Erlfang\estimates\maturation\Graphs/c/c_mul_wo_si.dta" , replace




